//完美运动框架
//多物体运动，不能共用一个计时器，应该给每一个物体设置一个计时器
//缓冲运动
function sport(obj,json,fn){
	//1.先清除上一次的计时器
	clearInterval(obj.timer);
	//2.开启新的计时器
	obj.timer = setInterval(function(){
		var stop = true; //假设所有的属性都已经到达了目标值
		for(var attr in json){
			//1.获取当前值
	//		let cur = parseInt(getStyle(obj,attr));
	//		let cur = parseInt(parseFloat(getStyle(obj,attr)) * 100);
			let cur = 0;
			if(attr == "opacity"){
				cur = parseInt(parseFloat(getStyle(obj,attr)) * 100);
			}else{
				cur = parseInt(getStyle(obj,attr));
			}
	//		console.log(cur);
			//2.计算速度
			let speed = (json[attr] - cur) / 8;
			speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
			//3.检测停止
			if(cur != json[attr]){
				stop = false;
			}
			//运动
//			obj.style[attr] = cur + speed + "px";
//			obj.style.opacity = (cur + speed) / 100;
//			obj.style.filter = "alpha(opacity=" + (cur + speed) + ")";
			if(attr == "opacity"){
				obj.style.opacity = (cur + speed) / 100;
				obj.style.filter = "alpha(opacity=" + (cur + speed) + ")";
			}else{
				obj.style[attr] = cur + speed + "px";
			}
//			console.log(json[attr] + ":" + cur + ":" + speed);
		}
		
		
		if(stop){
			//停止计时器
			clearInterval(obj.timer);
			if(fn){
			fn()
			}
		}
	},30);
}
//获取非行内样式
function getStyle(obj,attr){
	return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj,1)[attr];
}
